<!DOCTYPE html>
<html style = "height:100%">
<head>
    <meta charset="utf-8" />
    <title>易吧，开创新的生活</title>
</head>
<link rel="stylesheet" href="css/main.css" type = "text/css">
<link rel="stylesheet" href="css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="css/div.css" type="text/css">
<link rel="stylesheet" href="http://jrain.oscitas.netdna-cdn.com/tutorial/css/fontawesome-all.min.css" />
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquerysession.js"></script>
<script src="js/bootstrap-paginator.min.js"></script>
<script src="js/xs.js"></script>
<script charset="utf-8" src="js/city.js"></script>
<script charset="utf-8" src="js/date.js"></script>

<body style = "height:100%">
<nav class = "navbar nav_bar" role = "navigation">
    <div class="webset_info">
        <ul class="contact_phone">
            <li class="phone_ego">
                <i class="phone_icon"></i>
                <span>CONTACT: XXX-XXXX-XXXX</span>
            </li>
            <li class="phone_append">不知道写啥，二手书今天半价？</li>
        </ul>
    </div>
    <!-- 导航栏样式 bootstrap 实现-->
    <div class = "container-fluid" style="margin-top: 20px;">
        <div class="navbar-header logo_container">
            <a class="navbar-left" href="https://github.com/yanguojun123/YB" target="_blank">
                <img class = "logo" alt="Brand" src="image/logo_main.png" height="20">
            </a>
        </div>
        <div class="nav navbar-nav navbar-right loginandreg"  >
            <a id="portrait" style="cursor: pointer"  >
                <li>
                    <img src="../main_page/image/un_logged.png">
                </li>
                <p id="loginandreg_pos">登录</p>
            </a>
        </div>
        <!-- 这里添加登录的弹出框 -->

        <div class="nav navbar-nav navbar-right button_menu">
            <ul class="nav navbar-nav buttons">
                <li class="active"><a href="#">功能界面</a></li>
                <li><a href="../personal_page/chat_html/Personal_index.html">个人主页</a></li>
                <li><a href="#">关注我们</a></li>

            </ul>
        </div>
    </div>

</nav>
<div class = "input-group col-md-3 search_box">
    <!-- 搜索框 -->
    <input type = "text" class="search_input" value="请输入想要查询的内容" onfocus="this.value = '';" onblur="if(this.value == ''){this.value = '请输入想要查询的内容';}">
    <input type="submit" class="search_btn" value="搜索">
</div>
<div class = "main">
    <div class = "container-fluid contain">
        <!-- 容器，用于承载所有需要显示的元件 -->
        <div class="row main_disp_below">
            <!-- 主窗体 -->
            <div class="main_disp_header">
            </div>
            <div class = "main_disp">
                <!-- 界面显示的主体，分为左中右三个 -->
                <div class = "col-md-2 left_select_panel">
                    <!--
                        左边的导航栏，用于显示二手书和失物招领
                    -->
                    <!--
                        左边，这里采用模板的样式，尽量与背景和主体契合，不要选择太深的颜色和太扁平化的侧边栏
                    -->
                    <h3 class="bookClassHeader">二手书相关信息</h3>
                    <ul class="bookCatogries">
                        <li><a id="b1" href="main.html">购买二手书</a></li>
                        <li><a id="b2" href="mainadd.html">发布二手书</a></li>
                        <li><a id="b3" href="mainsearch.html">搜索二手书</a></li>
                    </ul>
                    <h3 class="swapClassHeader">失物招领信息</h3>
                    <ul class="swapCatogries">
                        <li><a id="s1" href="ShiWuZhaoling.html?lost_or_pick=lost" >失物信息</a></li>
                        <li><a id="s2" href="ShiWuZhaoling.html?lost_or_pick=pick" >招领信息</a></li>
                        <li><a id="s3" href="AddXinxi.html">免费发布信息</a></li>
                        <li><a id="s4" href="Search.html">搜索信息</a></li>
                    </ul>
                    <div class="moreInfo">
                    </div>
                </div>
                <div class = "col-md-7 " height="150px">
                    <!--
                        中间的显示，内容根据左边的选择进行变动
                    -->
                    <!-- 中间，我觉得左右两边的夹缝可以再窄一点，这里的 height 被重新设置为400，之后填充时取消 -->
                    <div id="content" class="content">
                        <div class="fabuxinxi" style="margin-left:20px;margin-right:20px;margin-top:20px;">
                            <form method="post"
                                  action="Search.html"
                                  enctype="multipart/form-data"
                                  class="form-group form-horizontal">
                              <div class="form-group">
                                <label for="inputcategory" class="col-sm-1 control-label">类别</label>
                                <div class="col-sm-3">
                                    <select name="leibie" class=" form-control">
                                        <?php
                                            if($_POST["leibie"]=="lost")
                                                echo "<option selected=\"lost\">找寻失物</option>";
                                            else
                                                echo "<option selected=\"pick\">招领启事</option>";
                                        ?>

                                        <option value="lost">找寻失物</option>
                                        <option value="pick">招领启事</option>
                                    </select>
                                </div>
                                <label for="inputcategory" class="col-sm-1 control-label">标签</label>
                                <div class="col-sm-2">
                                  <select name="biaoqian" class=" form-control">
                                      <?php
                                      if($_POST["biaoqian"])
                                          echo "<option selected=".$_POST["biaoqian"].">".$_POST["biaoqian"]."</option>";
                                      ?>
                                      <option value="钱包">钱包</option>
                                      <option value="证件">证件</option>
                                      <option value="卡类">卡类</option>
                                      <option value="印章">印章</option>
                                      <option value="钥匙">钥匙</option>
                                      <option value="衣服">衣服</option>
                                      <option value="手机">手机</option>
                                      <option value="首饰">首饰</option>
                                      <option value="票据">票据</option>
                                      <option value="数码">数码</option>
                                      <option value="电脑">电脑</option>
                                      <option value="包裹">包裹</option>
                                      <option value="宠物">宠物</option>
                                      <option value="其他">其他</option>
                                  </select>
                                </div>
                                <label for="inputcategory" class="col-sm-1 control-label">地点</label>
                                <div class="col-sm-3">
                                  <select name="didian" class="form-control">
                                      <?php
                                      if($_POST["didian"])
                                          echo "<option selected=".$_POST["didian"].">".$_POST["didian"]."</option>";
                                      ?>
                                      <option value="市南区">市南区</option>
                                      <option value="市北区">市北区</option>
                                      <option value="四方区">四方区</option>
                                      <option value="黄岛区">黄岛区</option>
                                      <option value="崂山区">崂山区</option>
                                      <option value="李沧区">李沧区</option>
                                      <option value="城阳区">城阳区</option>
                                      <option value="胶州市">胶州市</option>
                                      <option value="即墨市">即墨市</option>
                                      <option value="平度市">平度市</option>
                                      <option value="胶南市">胶南市</option>
                                      <option value="莱西市">莱西市</option>
                                  </select>
                                </div>
                              </div>

                              <div class="form-group">
                                <label for="inputcategory" class="col-sm-1 control-label">时间</label>
                                <div class="col-sm-2">
                                  <select name="year" id="year" class="form-control" onChange="setDay();">
                                    <script type="text/javascript">getYear();</script>
                                  </select>
                                </div>
                                <div class="col-sm-2">
                                  <select name="month" id="month"  class="form-control" onChange="setDay()">
                                    <script type="text/javascript">getMonth();</script>
                                  </select>
                                </div>
                                <div class="col-sm-2">
                                  <select name="day"  class="form-control" id="day">
                                    <script type="text/javascript">setDay();</script>
                                  </select>
                                </div>

                                <label for="inputcategory" class="col-sm-1 control-label">颜色</label>
                                <div class="col-sm-2">
                                  <select name="color" class="form-control">
                                      <?php
                                      if($_POST["color"])
                                          echo "<option selected=".$_POST["color"].">".$_POST["color"]."</option>";
                                      ?>
                                      <option value="红色">红色</option>
                                      <option value="橙色">橙色</option>
                                      <option value="黄色">黄色</option>
                                      <option value="绿色">绿色</option>
                                      <option value="青色">青色</option>
                                      <option value="蓝色">蓝色</option>
                                      <option value="紫色">紫色</option>
                                      <option value="灰色">灰色</option>
                                      <option value="粉色">粉色</option>
                                      <option value="黑色">黑色</option>
                                      <option value="白色">白色</option>
                                      <option value="棕色">棕色</option>
                                      <option value="其他">其他</option>
                                  </select>
                                </div>
                                <div class="col-sm-2">
                                  <button type="submit" name="queding" class="btn btn-info">筛选</button>
                                </div>


                              </div>



                              <input name="xianshi" id="xianshi" type="hidden" value="Y">
                              <input name="miaoshu" id="miaoshu" type="hidden" >
                              
                              
                              
                              
                              
                            </form>                    
                          </div>


                        </div>

                        <?php
                        set_error_handler('myerror');
                        function myerror() {}
                        function MinOfArray(&$arr){//求一个数组中元素值最小的下标
                            $min=10000;
                            $minindex=0;
                            for($y=0;$y<count($arr);$y++)
                                if($arr[$y]<$min){
                                    $min=$arr[$y];
                                    $minindex=$y;
                                }
                            return $minindex;
                        }
                        function MaxOfArray(&$arr){//求一个数组中元素值最大的下标
                            $max=0;
                            $maxindex=0;
                            for($y=0;$y<count($arr);$y++)
                                if($arr[$y]>$max){
                                    $max=$arr[$y];
                                    $maxindex=$y;
                                }
                            return $maxindex;
                        }
                        include('Server/ConnectMysql.php');
                        mysqli_query($connect,'SET names UTF8');
                        $leibie=$_POST["leibie"];
                        $biaoqian=$_POST["biaoqian"];
                        $didian="青岛市"+$_POST["didian"];
                        $color=$_POST["color"];
                        $shijian=$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
                        if(!empty($_POST['xianshi'])){
                            $xianshi=$_POST['xianshi'];
                        }
                        else $xianshi="N";
                        if($leibie=="lost"){
                            $query="select * from lostproperty";
                        }
                        else if($leibie=="pick"){
                            $query="select * from pickedproperty";
                        }
                        $id_array = array();
                        $xiangsidu_array=array();
                        for($x=0;$x<4;$x++){//这个4可以更改，表示最匹配的4个
                            $id_array[$x]=0;
                            $xiangsidu_array[$x]=0;
                        }
                        $result=mysqli_query($connect,$query);
                        while($result_row=mysqli_fetch_row($result)){
                            $xiangsidu=0;
                            if($result_row[5]==$biaoqian) $xiangsidu+=25;//标签占比25%
                            if($result_row[4]==$didian)   $xiangsidu+=25;//地点占比25%
                            if($result_row[3]==$shijian)  $xiangsidu+=30;//时间占比30%
                            else{
                                $first=date_create($result_row[3]);
                                $end=date_create($shijian);
                                $days=date_diff($first,$end)->days;

                                if($days==-1 || $days==1 ) $xiangsidu+=20;
                                else if($days==-2 || $days==2 ) $xiangsidu+=10;
                            }
                            if($result_row[11]==$color)   $xiangsidu+=20;//颜色占比20%
                            if($xiangsidu>=$xiangsidu_array[MinOfArray($xiangsidu_array)]){
                                $id_array[MinOfArray($xiangsidu_array)]=$result_row[0];
                                $xiangsidu_array[MinOfArray($xiangsidu_array)]=$xiangsidu;
                            }
                        }

                        $count=0;
                        while($count<4) {
                            $id=$id_array[MaxOfArray($xiangsidu_array)];
                            if($id!=0) {
                                if ($leibie == "lost") {
                                    $query = "select title,Picture1 from lostproperty where lostPropertyId = '$id' ";
                                } else if ($leibie == "pick") {
                                    $query = "select title,Picture1 from pickedproperty where pickedPropertyId = '$id' ";
                                }
                                $result_shiwushow = mysqli_query($connect, $query);
                                $row_shiwushow = mysqli_fetch_row($result_shiwushow);
                                ?>
                                <div class="subcontent" <?php if ("Y" != $xianshi) echo "style=\"display:none\""; ?> >
                                    <div class="subcon_photo" align="center">
                                        <a href="ShiWuPage.html?id=<?php echo $id; ?>&lost_or_pick=<?php echo $leibie ?>">
                                            <img width="100" height="200"
                                                 src="data:image/jpg;base64,<?= base64_encode($row_shiwushow[1]) ?>">
                                        </a>
                                    </div>
                                    <div title="标题" align="center" style="margin-left:10%;weight:100%;">
                                        <a href="ShiWuPage.html?id=<?php echo $id; ?>&lost_or_pick=<?php echo $leibie ?>" style="font-size:15px;
                                             text-decoration:none;"><?php echo $row_shiwushow[0]; ?></a>
                                        <br/>
                                        匹配度：<?php echo round($xiangsidu_array[MaxOfArray($xiangsidu_array)]) . '%'; ?>
                                    </div>
                                </div>
                                <?php
                            }
                            else{
                                ?>
                                <div class="subcontent" <?php if ("Y" != $xianshi) echo "style=\"display:none\""; ?> >
                                </div>
                                <?php
                            }
                            $xiangsidu_array[MaxOfArray($xiangsidu_array)]=-1;
                            $count++;
                        }
                        ?>

                    </div>
                </div>
                <div class = "col-md-3 right_info_panel">
                          <h2 class="rightheader">热度最高</h2>
                          <ul id="heat">
                            <li><span id="right1"></span><a>三体</a></li>
                          </ul>
                    <!--
                    右边的显示，内容根据左边的选择进行变动；
                    当左侧选择的是二手书相关，右侧显示最火热的二手书；
                    当左侧选择的是失物招领相关，右侧显示（不知道显示什么，说不定可以关掉？估计关掉很难看）
                    -->
                </div>
            </div>
        </div>
    </div>
</div>
<div class = "foot">
    <!-- 角注，呈现版权信息、公司团队信息等 -->
    <div class="container-fluid foot_container">
        <div class="footer-grid foot_panel_1 shrink">
            <h3>完全不知道应该写什么</h3>
            <ul class="foot_list">
                <li><a href="#">项目一</a></li>
                <li><a href="#">项目二</a></li>
                <li><a href="#">项目三</a></li>
                <li><a href="#">项目四</a></li>
            </ul>
        </div>
        <div class="footer-grid foot_panel_2 shrink">
            <h3>第二栏的标题</h3>
            <ul class="foot_list">
                <li><a href="#">项目一</a></li>
                <li><a href="#">项目二</a></li>
                <li><a href="#">项目三</a></li>
                <li><a href="#">项目四</a></li>
            </ul>
        </div>
        <div class="footer-grid foot_panel_3 shrink">
            <h3>第三栏的标题</h3>
            <ul class="foot_list">
                <li><a href="#">项目一</a></li>
                <li><a href="#">项目二</a></li>
                <li><a href="#">项目三</a></li>
                <li><a href="#">项目四</a></li>
                <li><a href="#">项目五</a></li>
            </ul>
        </div>
        <div class="footer-grid foot_panel_4 shrink">
            <h3>第四栏的标题</h3>
            <ul class="foot_list">
                <li><a href="#">项目一</a></li>
                <li><a href="#">项目二</a></li>
            </ul>
        </div>
        <div class="footer-grid foot_panel_5 shrink">
            <h3>第五栏的标题</h3>
            <ul class="foot_list">
                <li><a href="#">项目一</a></li>
                <li><a href="#">项目二</a></li>
                <li><a href="#">项目三</a></li>
            </ul>
        </div>
    </div>
    <div class="foot_license">
        Copyright © 2019.Company name All rights reserved.More Templates 模板之家 - Collect from 网页模板(没错我故意的，嘿嘿)
    </div>
</div>

<div id="login_window">
    <div id="login_window_container">
        <div class="login_input">
            <input type="text" id="logInput1" onfocus="this.value='';" onblur="inputInfo1(this.id)" name="account" value="account">
        </div>
        <div class="login_input">
            <input type="password" id="logInput2"
                   onfocus="this.value='';" onblur="inputInfo2(this.id)"
                   name="passwd" value="password">
        </div>
        <div id="btns">
            <button onclick="login()">Login</button>
            <button onclick="registerBTN()">Register</button>
        </div>
    </div>
</div>
<div id="grayBackground">

</div>
<div id="register_window">
    <div id="register_window_container">
        <!-- 这里的东西就多了，先写着吧 -->
        <div id="registerHeader">
            <h2>新用户注册</h2>
        </div>
        <div id="regisSpan">
            <h4>您的注册 ID 为: <span id="registerID">123456789</span></h4>
        </div>
        <div id="registerInputs">
            <div id="regisNickname">
                <input type="text" placeholder="请输入您的昵称">
            </div>
            <div id="regisEmail">
                <input type="text" placeholder="请输入注册邮箱" onblur="verifyEmail(this)">
            </div>
            <div id="regisPasswd">
                <input type="password" placeholder="请输入密码" onblur="verifyPasswd(this)">
            </div>
            <div id="regisPasswdAgain">
                <input type="password" placeholder="请再次确认密码">
            </div>
        </div>
        <div id="registerButtons">
            <button>注册</button>
            <button onclick="register_cancel()">取消</button>
        </div>
    </div>
</div>

</body>
<script>
for(let i=1;i<=3;i++)
  $("#b"+i).css({"font-size":"10px","color":"black"});
for(let i=1;i<=4;i++)
  $("#s"+i).css({"font-size":"10px","color":"black"});
$("#s4").css({"font-size":"20px","color":"red"});
//从数据库异步获取最新热度的内容展示到右侧面板
function rightget(){
  $("#heat").empty();
  for(let i=0;i<6;i++){
    $("#heat").append("<li id='right"+i+"'><span><a>信"+i+"</a></span></li>");
    $("#right"+i+"").xs999(Math.round(Math.random()*30));
    $("#right"+i+"").hover(function(){
      $(this).children().children().css({"font-size":"28px","color":"#2bae85","transition":"0.2s"});
    },function(){
      $(this).children().children().css({"font-size":"18px","color":"#ffffff"});
    });
    $("#right"+i+"").click(function(){
      alert($(this).children().children().text())
    });
  }

  
}	 
rightget();
  let tuser=sessionStorage.getItem("user");
  if(tuser==null){
    console.log("未登录")
  }
  else{
    console.log("登录",tuser)
  }
</script>
<script src="js/main.js"></script>
</html>
